package com.twu.biblioteca;

import java.io.BufferedReader;
import java.util.*;

/**
 * Created by abhishekpuri on 10/6/14.
 */
public class Menu {


    private IOHandler ioHandler;
    private ArrayList<String> Options;

    public Menu(ArrayList<String> options) {
        Options= options;
        ioHandler=new IOHandler();
    }

    public Menu(ArrayList<String> options,BufferedReader inStream) {
        this.Options=options;
        ioHandler=new IOHandler(inStream);
    }

    public void showMenuOptions() {
        ioHandler.printlnToConsole("Choose the desired option");
        for(int i=0;i< Options.size();i++) {
            ioHandler.printlnToConsole((i+1) + ". " + Options.get(i));
        }
    }

    public int readUserInput() {
        ioHandler.printToConsole("Enter the choice : ");
        Integer choice= ioHandler.readInt();
        if(choice == null || choice > Options.size()){
            ioHandler.printlnToConsole("Select a valid option!");
            return -1;
        }
        return choice;
    }

}
